package com.spj.facory;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @author spj
 */
public class PeopleFactoryFourPrototype {
    static Map<String, String> map;
    static Properties properties;

    static {
        map = new HashMap();
        properties = new Properties();
        try {
            properties.load(PeopleFactoryFourPrototype.class.getClassLoader().getResourceAsStream("country.properties"));
            Set<String> set = properties.stringPropertyNames();
            for (String str : set) {
                String country = properties.getProperty(str);
                map.put(str, country);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static Object getBean(String race) throws Exception {
        String country=map.get(race);
        Class peopleClass = Class.forName(country);
        Object object = peopleClass.getConstructor().newInstance();
        return object;

    }


}
